﻿@{
    List<SmallJob.Model.Category> catgories = null;
    if (ViewData["categories"] != null)
    {
        catgories = ViewData["categories"] as List<SmallJob.Model.Category>;
    }
    else
    {
        catgories = new SmallJob.Services.Implements.CategoryService(new SmallJob.Data.DatabaseFactory()).All().ToList();
    }
    var user = new SmallJob.Model.User();
    var isFbAcc = false;
    var verify = new SmallShop.Services.Code.VerifyAccount();
    if (User.Identity.IsAuthenticated)
    {
        user = SmallShop.Services.Implements.UtilityService.GetProperName(User.Identity.Name);
        isFbAcc = user.Password == null;
        verify = SmallJob.Services.Code.UserUtility.GetVerifyAccount(user.VerifyStatus);
    }
}
<!DOCTYPE html>
<html>
<head>
    @Html.Partial("SharedMetaDataPV")
    @if (IsSectionDefined("DifMetaData"))
    {
        @RenderSection("DifMetaData")
    }

    @if (IsSectionDefined("FBMeta"))
    {
        @RenderSection("FBMeta")
    }
    <link rel="shortcut icon" href="/Content/img/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/Content/img/favicon.ico" type="image/x-icon">
    <link href="@Url.Content("~/Content/css/bootstrap.min.css")" rel="stylesheet" media="screen">
    <!-- <link href="@Url.Content("~/Content/css/bootstrap-responsive.min.css")" rel="stylesheet"> -->
    <link href="@Url.Content("~/Content/css/responsiveslides.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/css/main.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/css/bootstrap-fileupload.min.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/css/bootstrap-wysihtml5-0.0.2.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/css/jquery.tagit.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/css/jquery-ui.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/css/tagit.ui-zendesk.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/css/bootstrap-extends.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/css/datepicker.css")" rel="stylesheet" media="screen">
    <link href="@Url.Content("~/Content/plugin/rateit/rateit.css")" rel="stylesheet" media="screen">
    <script src="@Url.Content("~/Content/js/jquery.min.js")"></script>
    <script src="@Url.Content("~/Scripts/ui/jquery-ui.js")"></script>
    <script src="@Url.Content("~/Content/js/jquery.form.js")"></script>
    <script src="@Url.Content("~/Content/js/bootstrap-datepicker.js")"></script>

</head>

<body>
    <script>
        (function (i, s, o, g, r, a, m) {
            i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
                (i[r].q = i[r].q || []).push(arguments)
            }, i[r].l = 1 * new Date(); a = s.createElement(o),
            m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
        })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

        ga('create', 'UA-24491884-11', 'viecnho.com');
        ga('send', 'pageview');

    </script>
    <div id="fb-root">
    </div>
    <div class="navbar navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container-fluid">
                <ul class="nav">
                    <li><a class="header-logo" href="@Url.Action("Index", "Home")">
                        <img src="@Url.Content("~/Content/img/viecnho-logo-small.png")"></a></li>
                    <li class="dropdown">
                        @{Html.RenderAction("CategoryPartialView", "Home");}
                    </li>
                    <li class="dropdown">
                        <a class="header-menu dropdown-toggle" href="#" data-toggle="dropdown"><i class="icon-map-marker"></i>&nbsp;Địa điểm <b class="caret"></b></a>
                        <ul class="dropdown-menu" role="menu" aria="" labelledby="header-username-menu">
                            <li><a href="@Url.Action("Location", "Provide", new { id = "1" })">Hà Nội</a></li>
                            <li><a href="@Url.Action("Location", "Provide", new { id = "2" })">TP.Hồ Chí Minh</a></li>
                            <li><a href="@Url.Action("Location", "Provide", new { id = "3" })">Hải Phòng</a></li>
                            <li><a href="@Url.Action("Location", "Provide", new { id = "4" })">Đà Nẵng</a></li>
                            <li><a href="@Url.Action("Location", "Provide", new { id = "5" })">Cần Thơ</a></li>
                            <li><a href="@Url.Action("Location", "Provide", new { id = "64" })">Toàn Quốc</a></li>
                        </ul>
                    </li>
                    <li><a href="http://camnang.viecnho.com" target="_blank"><i class="icon-book"></i>&nbsp;Cẩm nang</a></li>
                </ul>
                @using (Html.BeginForm("Search", "Provide", FormMethod.Post, new { Class = "navbar-search", id = "form-search" }))
                {
                    <input type="text" name="search" class="span2 search-query" placeholder="Từ khóa tìm kiếm" />
                }
                <ul class="nav pull-right">
                    @if (User.Identity.IsAuthenticated && user != null)
                    {
                        string personlink = Url.Content("~/") + (user.UserName == null || user.UserName == "" ? user.ID.ToString() : user.UserName);
                        <div id="loaded"></div>        
                        <li class="dropdown">
                            <a class="header-menu dropdown-toggle" href="#" data-toggle="dropdown"><span class="badge badge-important" id="unprocess-order">0</span>&nbsp;<i class="icon-shopping-cart"></i>&nbsp;<b class="caret"></b></a>
                            <ul class="dropdown-menu" role="menu" aria="" labelledby="header-username-menu">
                                <li><a href="@Url.Action("ManageService", "Order")"><span class="badge badge-important" id="count-service-process">0</span>&nbsp;Cần làm</a></li>
                                <li><a href="@Url.Action("ManageOrder", "Order")"><span class="badge badge-important" id="count-order-waitdone">0</span>&nbsp;Đơn hàng</a></li>
                            </ul>
                        </li>
                        <li><a class="header-menu" href="@Url.Action("Inbox", "Personal")"><span class="badge badge-important" id="unread-mess">0</span>&nbsp;<i class="icon-envelope"></i></a></li>
                        <li><a class="header-menu" id="show-system-notify" href="#"><span class="badge badge-important" id="unread-notify">0</span>&nbsp;<i class="icon-comment"></i></a></li>
                        <li class="dropdown">
                            <a class="header-menu dropdown-toggle" href="#" data-toggle="dropdown">@user.ProperName <b class="caret"></b></a>
                            <ul class="dropdown-menu" role="menu" aria="" labelledby="header-username-menu">
                                <li><a href="/them-dich-vu"><strong><i class="icon-plus"></i>&nbsp;Đăng dịch vụ</strong></a></li>
                                <li><a href="@personlink">Trang cá nhân</a></li>
                                <li><a href="#changeinfo" data-toggle="modal">Sửa thông tin</a></li>
                                @if (!verify.IsDoneAll())
                                {
                                    <li><a href="#shared-verifyaccount" data-toggle="modal">Xác thực tài khoản</a></li>
                                }
                                <li class="divider"></li>
                                <li><a href="#" id="logout">Thoát</a></li>
                            </ul>
                        </li>
                        <li>
                            <p class="nav-button"><a type="button" class="btn header-button btn-success" href="/vip">Lên tài khoản VIP</a></p>
                        </li>
                    }
                    else
                    {
                        <li><a class="header-menu" href="#login" data-toggle="modal"><i class="icon-user"></i>&nbsp;Đăng nhập</a></li>
                    }
                </ul>
            </div>
        </div>
        <div id="login" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
            <div class="modal-body">
                <p class="fb-login-button text-center">
                    <button class="btn-facebook" id="btn-fblogin">Đăng nhập bằng Facebook</button>
                </p>
                <p class="or-login text-center"><span class="or-text">hoặc điền</span></p>
                @using (Html.BeginForm("Login", "Home", FormMethod.Post, new { Class = "form-horizontal", id = "shared-login" }))
                {
                    <div id="shared-login-email" class="control-group">
                        <div class="controls vn-modal-input">
                            <div class="input-prepend">
                                <span class="add-on"><i class="icon-envelope"></i></span>
                                <input type="text" name="email" placeholder="Email">
                            </div>
                            <span class="help-inline"></span>
                        </div>
                    </div>
                    <div id="shared-login-password" class="control-group">
                        <div class="controls vn-modal-input">
                            <div class="input-prepend">
                                <span class="add-on"><i class="icon-edit"></i></span>
                                <input type="password" name="password" placeholder="Mật khẩu">
                            </div>
                            <span class="help-inline"></span>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls vn-modal-input">
                            <button type="submit" class="btn btn-danger" id="shared-login-btn">Đăng nhập</button>
                        </div>
                    </div>
                }
            </div>
        </div>

        <div id="post-service" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-body">
                <h4 class="muted text-center vn-modal-headline">Thông tin dịch vụ của bạn</h4>
                @using (Html.BeginForm("CompleteSignup", "Home", FormMethod.Post, new { Class = "form-horizontal", id = "form-service" }))
                {
                    <fieldset>
                        <div id="group-title" class="control-group">
                            <div class="controls vn-modal-input-2">
                                <div class="input-prepend">
                                    <span class="add-on">Tiêu đề</span>
                                    <input name="title" class="input-large" placeholder="Tiêu đề dịch vụ" type="text">
                                </div>
                                <span class="help-inline"></span>
                            </div>
                        </div>
                        <div id="group-description" class="control-group">
                            <div class="controls vn-modal-input-2">
                                <div class="input-prepend">
                                    <label>Mô tả dịch vụ</label>
                                    <textarea rows="4" name="description" id="description"></textarea>
                                </div>
                                <span class="help-inline"></span>
                            </div>
                        </div>
                        <div id="group-location" class="control-group">
                            <div class="controls vn-modal-input-2">
                                <div class="input-prepend">
                                    <span class="add-on">Địa điểm</span>
                                    <input id="location" name="location" class="input-xlarge" placeholder="tình/thành phố" type="text">
                                </div>
                                <span class="help-inline"></span>
                            </div>
                        </div>
                        <div id="group-price" class="control-group">
                            <div class="controls vn-modal-input-2">
                                <div class="input-prepend">
                                    <span class="add-on">Giá</span>
                                    <input id="price" name="price" class="input-xlarge" placeholder="Giá dịch vụ của bạn" type="text">
                                </div>
                                <span class="help-inline"></span>
                            </div>
                        </div>
                        <div id="group-file" class="control-group">
                            <div class="controls vn-modal-input-2">
                                <h4>Hình ảnh</h4>
                                <div class="fileupload fileupload-new" data-provides="fileupload">
                                    <div class="fileupload-preview thumbnail" style="width: 200px; height: 150px;"></div>
                                    <div>
                                        <span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" /></span>
                                        <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Button -->
                        <div class="control-group">
                            <div class="controls vn-modal-input-2">
                                <button id="post" name="post" class="btn btn-primary">Lưu</button>
                            </div>
                        </div>
                    </fieldset>
                }
            </div>
        </div>
    </div>
    <div class="fbhiddenform" style="display: none">
        @using (Html.BeginForm("LoginFB", "Home", FormMethod.Post, new { id = "form-loginFB" }))
        {
            <input type="hidden" name="fbID" id="fbID" value="" />
            <input type="hidden" name="fbname" id="fbname" value="" />
            <input type="hidden" name="fbemail" id="fbemail" value="" />
        }
        @using (Html.BeginForm("UploadAvatar", "User", FormMethod.Post, new { style = "display:none", id = "shared-uploadavatar-hidden", enctype = "multipart/form-data" }))
        {
            <input style="visibility: hidden" id="uploadavatar-hidden-file" type="file" name="avatarImage" />
        }
    </div>
    <div id="changeinfo" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Sửa thông tin cá nhân</h3>
        </div>
        <div class="modal-body">

            @if (!isFbAcc)
            {
                <ul id="tabinfo" class="nav nav-tabs">
                    <li class="active"><a href="#profile" data-toggle="tab">Thông tin</a></li>
                    <li class=""><a href="#password" data-toggle="tab">Đổi mật khẩu</a></li>
                </ul>
            }
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane fade  active in" id="profile">
                    @using (Html.BeginForm("SaveProfile", "Personal", FormMethod.Post, new { Class = "form-horizontal", id = "shared-changeprofile" }))
                    {
                        <fieldset>
                            <div id="shared-changeprofile-storename" class="control-group viecnho-control-group">
                                <div class="controls vn-modal-input-2">
                                    <div class="input-prepend input-fullwidth">
                                        <span class="add-on">viecnho.com/</span>
                                        <input name="storename" class="input-wrapper input-xlarge" placeholder="nickname của bạn" value="@user.UserName" type="text" />
                                    </div>
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <div id="shared-changeprofile-propername" class="control-group viecnho-control-group">
                                <div class="controls vn-modal-input-2">
                                    <div class="input-prepend input-fullwidth">
                                        <span class="add-on">Tôi tên là</span>
                                        <input name="propername" class="input-wrapper input-xlarge" placeholder="Họ tên đầy đủ của bạn" value="@user.ProperName" type="text">
                                        <span class="help-block signuptep2-help">Dùng tên thật giúp tài khoản của bạn đáng tin hơn.</span>
                                    </div>
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <div id="shared-changeprofile-city" class="control-group viecnho-control-group">
                                <div class="controls vn-modal-input-2">
                                    <div class="input-prepend input-fullwidth">
                                        <span class="add-on">Tôi sống ở</span>
                                        <select name="city">
                                            @foreach (var item in SmallShop.Services.Implements.UtilityService.GetCities())
                                            {
                                                if (user.Location == item.Name)
                                                {
                                                <option selected="selected" value="@item.Name">@item.Name</option>
                                                }
                                                else
                                                {
                                                <option value="@item.Name">@item.Name</option>
                                                }
                                            }
                                        </select>
                                    </div>
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <div id="shared-changeprofile-job" class="control-group viecnho-control-group">
                                <div class="controls vn-modal-input-2">
                                    <div class="input-prepend input-fullwidth">
                                        <span class="add-on">Tôi đang làm</span>
                                        <input name="job" class="input-wrapper input-xlarge" value="@user.Job" placeholder="nghề nghiệp, công việc của bạn" type="text">
                                    </div>
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <div id="shared-changeprofile-phone" class="control-group viecnho-control-group">
                                <div class="controls vn-modal-input-2">
                                    <div class="input-prepend input-fullwidth">
                                        <span class="add-on">Số điện thoại</span>
                                        <input name="phone" class="input-wrapper input-xlarge" value="@user.Phone" placeholder="Số di động của bạn" type="text">
                                        <span class="help-block signuptep2-help">Dùng số di động thật giúp bạn nhận thông báo qua sms.</span>
                                    </div>
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <!-- Button -->
                            <div class="control-group viecnho-control-group">
                                <div class="controls vn-modal-input-2">
                                    <button id="shared-changeprofile-btn" name="save" class="btn btn-primary">Lưu</button>
                                </div>
                            </div>
                        </fieldset>
                    }
                </div>
                @if (!isFbAcc)
                {
                    <div class="tab-pane fade" id="password">

                        <h4 class="muted text-center vn-modal-headline">Thay đổi mật khẩu</h4>
                        @using (Html.BeginForm("SaveAccount", "Personal", FormMethod.Post, new { Class = "form-horizontal", id = "shared-changepassword" }))
                        {
                            <fieldset>
                                <div id="shared-changepassword-oldpassword" class="control-group">
                                    <div class="controls vn-modal-input-2">
                                        <div class="input-prepend">
                                            <span class="add-on">Mật khẩu hiện tại</span>

                                            <input name="oldpassword" class="input-xlarge" placeholder="Mật khẩu hiện tại của bạn" type="password">
                                        </div>
                                        <span class="help-inline"></span>
                                    </div>
                                </div>
                                <div id="shared-changepassword-newpassword" class="control-group">
                                    <div class="controls vn-modal-input-2">
                                        <div class="input-prepend">
                                            <span class="add-on">Mật khẩu mới</span>
                                            <input id="newpassword" name="newpassword" class="input-xlarge" placeholder="nhập mật khẩu mới" type="password">
                                        </div>
                                        <span class="help-inline"></span>
                                    </div>
                                </div>
                                <div id="shared-changepassword-repassword" class="control-group">
                                    <div class="controls vn-modal-input-2">
                                        <div class="input-prepend">
                                            <span class="add-on">Nhập lại mật khẩu mới</span>
                                            <input id="repassword" name="repassword" class="input-xlarge" placeholder="nhập lại mật khẩu mới" type="password">
                                        </div>
                                        <span class="help-inline"></span>
                                    </div>
                                </div>
                                <!-- Button -->
                                <div class="control-group">
                                    <div class="controls vn-modal-input-2">
                                        <button id="shared-changepassword-btn" name="save" class="btn btn-primary">Lưu</button>
                                    </div>
                                </div>
                            </fieldset>
                        }
                    </div>
                }
            </div>
        </div>
    </div>
    @RenderBody()
    @if (User.Identity.IsAuthenticated)
    {
        <div id="shared-verifyaccount" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>Xác thực tài khoản bằng 1 trong 2 cách</h3>
            </div>
            <div class="modal-body">
                @*<div class="progress progress-info progress-striped active" id="verifyaccount-process">
                    <div class="bar" style="width: @(verify.GetPercentDone())%;"></div>
                </div>*@
                <div class="tab-pane fade in fb-verify-panel" id="verifyaccount-fb">
                    <h4 class="muted text-center vn-modal-headline">Xác thực bằng tài khoản Facebook</h4>
                    <div class="verify-message">
                        <p class="fb-login-button text-center">
                            <button class="btn-facebook" id="verifyaccount-fb-btn">Xác thực Facebook</button>
                        </p>
                    </div>
                    <p class="text-info text-center">Chỉ 2 click để xác thực một cách nhanh chóng.</p>
                </div>

                <div class="tab-pane fade active in normal-verify-panel">
                    <h4 class="muted text-center vn-modal-headline">Hoặc xác thực theo 3 bước sau</h4>
                    <div id="verifyaccount-info">
                    </div>
                    @if (!verify.GetStatusOfStep(SmallShop.Services.Code.VerifyAccount.STEP_EMAIL))
                    {
                        <div id="verifyaccount-email">
                            <p><strong>Bước 1:</strong> Kiểm tra email @user.Email để lấy mã xác thực</p>
                            <form class="form-inline" id="shared-verifyemail">
                                <input type="text" class="input-medium" name="verifycode" placeholder="Mã xác thực">
                                <input type="submit" value="Xác thực email" id="shared-verifyemail-btn" class="btn" />
                                <a id="verifyaccount-email-generatecode" href="#">Gửi lại mã</a>
                            </form>
                        </div>
                    }
                    @if (!verify.GetStatusOfStep(SmallShop.Services.Code.VerifyAccount.STEP_NAME))
                    {
                        <div id="verifyaccount-name">
                            <p><strong>Bước 2:</strong> Điền họ tên đầy đủ:</p>
                            <form class="form-inline" id="shared-verifyname">
                                <input type="text" class="input-medium" name="name" placeholder="Điền tên thật của bạn">
                                <input type="submit" value="Xác thực họ tên" id="shared-verifyname-btn" class="btn" />
                            </form>
                            <p class="text-error">Họ và tên thật giúp tăng sự tin tưởng của người đặt dịch vụ.</p>
                        </div>
                    }
                    @if (!verify.GetStatusOfStep(SmallShop.Services.Code.VerifyAccount.STEP_PHONE))
                    {
                        <div id="verifyaccount-phone">
                            <p><strong>Bước 3:</strong> Điền số điện thoại</p>
                            <form class="form-inline" id="shared-verifyphone">
                                <input type="text" class="input-medium" name="phone" placeholder="Điền số di động của bạn">
                                <input type="submit" value="Xác thực số điện thoại" id="shared-verifyphone-btn" class="btn" />
                            </form>
                            <p class="text-error">Chỉ được dùng để gửi thông báo khi có đơn đặt hàng.</p>
                        </div>
                    }
                </div>
            </div>
        </div>
    }
    <div class="modal hide" id="shared-waitdialog" data-backdrop="static" data-keyboard="false">
        <div class="modal-header">
            <h1>Processing...</h1>
        </div>
        <div class="modal-body">
            <div class="progress progress-striped active">
                <div class="bar" style="width: 100%;"></div>
            </div>
        </div>
    </div>
    <div id="footer">
        <p class="text-center">Phiên bản thử nghiệm - ViecNho.com</p>
        <p class="text-center">Góp ý xin liên hệ <a href="mailto:sm@viecnho.com">sm@viecnho.com</a></p>
    </div>

    <script>
        window.fbAsyncInit = function () {
            FB.init({
                appId: '479862562081214', // App ID
                channelUrl: '//' + window.location.hostname + '/channel.html', // Channel File
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true  // parse XFBML
            });

            // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
            // for any authentication related change, such as login, logout or session refresh. This means that
            // whenever someone who was previously logged out tries to log in again, the correct case below
            // will be handled.
            FB.Event.subscribe('auth.authResponseChange', function (response) {
                // Here we specify what we do with the response anytime this event occurs.
                if (response.status === 'connected') {
                    if (response.status == "connected" && localStorage['autologin'] == 'true' && $('#loaded').length == 0) {
                        $('#fbID').val(response.authResponse.userID);
                        FB.api('/me', function (resp) {
                            $('#fbname').val(resp.name);
                            $('#fbemail').val(resp.email);
                            $.ajax({
                                type: "POST",
                                url: '@Url.Action("SignUpFB", "Home")',
                                data: $('#form-loginFB').serialize(), // serializes the form's elements.
                                success: function (d) {
                                    localStorage['autologin'] = true;
                                    window.location = window.location;
                                },
                            });
                        });
                    }
                    // }
                } else if (response.status === 'not_authorized') {
                    // In this case, the person is logged into Facebook, but not into the app, so we call
                    // FB.login() to prompt them to do so.
                    // In real-life usage, you wouldn't want to immediately prompt someone to login
                    // like this, for two reasons:
                    // (1) JavaScript created popup windows are blocked by most browsers unless they
                    // result from direct interaction from people using the app (such as a mouse click)
                    // (2) it is a bad experience to be continually prompted to login upon page load.
                    FB.login();
                } else {
                    // In this case, the person is not logged into Facebook, so we call the login()
                    // function to prompt them to do so. Note that at this stage there is no indication
                    // of whether they are logged into the app. If they aren't then they'll see the Login
                    // dialog right after they log in to Facebook.
                    // The same caveats as above apply to the FB.login() call here.
                    FB.login();
                }
            });
        };
    </script>
    <script src="@Url.Content("~/Content/js/bootstrap.min.js")"></script>
    <script src="@Url.Content("~/Content/js/bootstrap-fileupload.min.js")"></script>
    <script src="@Url.Content("~/Content/js/responsiveslides.min.js")"></script>
    <script src="@Url.Content("~/Content/js/jquery.showpassword.js")"></script>
    <script src="@Url.Content("~/Content/js/prettify.js")"></script>
    <script src="@Url.Content("~/Content/js/wysihtml5-0.3.0.js")"></script>
    <script src="@Url.Content("~/Content/js/bootstrap-wysihtml5.js")"></script>
    <script src="@Url.Content("~/Content/js/tag-it.min.js")"></script>
    <script src="@Url.Content("~/Content/js/controldisplay.js")"></script>          
    <script src="@Url.Content("~/Content/js/formAjax.js")"></script>
    <script src="@Url.Content("~/Content/plugin/rateit/jquery.rateit.min.js")"></script>
    @if (User.Identity.IsAuthenticated)
    {
        <script>
            //preload
            $.post("/Message/ShowNotifyPV?page=1", {}, function (data) {
                $('body').append(data);
            });
        </script>
    }
    <script>
        //facebook

        var app_id = '479862562081214';
        var app_secret = 'b58adcca0d8fa1e47fd12fc3ea18cca0';
        function getURLParameter(name) {
            return decodeURI(
                (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
            );
        }
        var code = getURLParameter('code');
        if (code != 'null') {
            window.location = (window.location).toString().replace('code=' + code, '');
        }

        // Load the SDK's source Asynchronously
        // Note that the debug version is being actively developed and might
        // contain some type checks that are overly strict.
        // Please report such bugs using the bugs tool.
        (function (d) {
            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
            if (d.getElementById(id)) { return; }
            js = d.createElement('script'); js.id = id; js.async = true;
            js.src = "//connect.facebook.net/en_US/all.js";
            ref.parentNode.insertBefore(js, ref);
        }(document));
        function fbEnsureInit(callback) {
            if (FB == undefined) {
                setTimeout(function () { fbEnsureInit(callback); }, 50);
            } else {
                if (callback) {
                    callback();
                }
            }
        }
        $('#btn-fblogin').click(function () {
            fbEnsureInit(function () {
                FB.getLoginStatus(function (response) {
                    if (response.status == "connected") {
                        $('#fbID').val(response.authResponse.userID);
                        FB.api('/me', function (resp) {
                            $('#fbname').val(resp.name);
                            $('#fbemail').val(resp.email);
                            $.ajax({
                                type: "POST",
                                url: '@Url.Action("SignUpFB", "Home")',
                                data: $('#form-loginFB').serialize(), // serializes the form's elements.
                                success: function (d) {
                                    localStorage['autologin'] = true;
                                    window.location = window.location;
                                },
                            });
                        });
                    } else {
                        FB.login(function (r) {
                            if (r.status == 'connected') {
                                localStorage['autologin'] = true;
                                FB.api('/me', function (resp) {
                                    $.post('@Url.Action("SignUpFB", "Home")', { fbID: resp.id, fbname: resp.name, fbemail: resp.email }, function (u) {
                                        FB.api('/me/viecnho:register', 'post', {
                                            account: 'http://viecnho.com/' + u.ID
                                        }, function (response) {
                                            FB.api('/me/picture?width=180&height=180', function (re) {
                                                $.post('@Url.Action("AddFBAvatar", "Home")', { fbID: u.FbID, url: re.data.url }, function (reval) {
                                                });
                                            });
                                        });
                                    });
                                });
                                }
                        }, { scope: 'email,user_status,publish_actions' });
                        }
                });
            });
        });
            $('#logout').click(function (e) {
                localStorage['autologin'] = false;
                window.location = '@Url.Action("LogOut", "Home")';
            });
            $(document).ready(function () {

                $('#show-system-notify').click(function () {
                    var that = this;
                    var popover = $('#notify-list-details');
                    if (popover.length !== 0) {
                        $(popover).fadeToggle('fast');
                        loadcountnotify();
                        prevent = false;
                    } else {
                        $.post("/Message/ShowNotifyPV?page=1", {}, function (data) {
                            $('body').append(data);
                            $('#notify-list-details').fadeToggle('fast');
                        });
                    }
                });

                $.post('@Url.Action("GetUnread", "Message")', function (data) {
                    if (data > 0) {
                        $('#unread-mess').text(data);
                    }
                });
                loadunreadorder();
                loadcountserviceprocess();
                loadcountorderwaitdone();
                loadcountnotify();
                if (window.location.hash == "#showverify") {
                    $('#shared-verifyaccount').modal({
                        show: true
                    });
                    window.location.hash = "";
                    //$('#singupstep2-modal').on('hide', function () {
                    //});
                }
            });
            function loadunreadorder() {
                $.post('@Url.Action("GetUnreadOrder", "Message")', function (data) {
                    if (data > 0) {
                        $('#unread-mess-order').text(data);
                    }
                });
            }
            function loadcountserviceprocess() {
                $.post('@Url.Action("GetCountServiceProcess", "Order")', function (data) {
                    if (data > 0) {
                        $('#count-service-process').text(data);
                        var data2 = $('#count-order-waitdone').text();
                        $('#unprocess-order').text(data * 1 + data2 * 1);
                    }
                });
            }
            function loadcountorderwaitdone() {
                $.post('@Url.Action("GetCountOrderWaitDone", "Order")', function (data) {
                    if (data > 0) {
                        $('#count-order-waitdone').text(data);
                        var data2 = $('#count-service-process').text();
                        $('#unprocess-order').text(data * 1 + data2 * 1);
                    }
                });
            }
        function loadcountnotify() {
            $.post('@Url.Action("GetCountNotify", "Message")', function (data) {
                        if (data > 0) {
                            $('#unread-notify').text(data);
                        }
                    });
                }
        @* $.post('@Url.Action("GetTimeExpire", "User")', { fbID: response.authResponse.userID }, function (value) {
            var temp = new Date().getTime();
            if (isNaN(value) || temp > parseInt(value)) {
                $.get('https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=' + app_id + '&client_secret=' + app_secret + '&fb_exchange_token=' + response.authResponse.accessToken, function (data) {
                    var str = data.split('&');
                    var accToken = str[0].replace('access_token=', '');
                    var timeExpire = parseInt(str[1].replace('expires=', ''));
                    var t = (new Date()).getTime();
                    $.post('@Url.Action("SaveAccessToken", "User")', { accToken: accToken, dateExpire: (t + timeExpire * 1000 - 864000000), fbID: response.authResponse.userID }, function () { });
                });
            }
        });*@
    </script>
</body>
</html>
